Matlab subplot之后在中央上方加标题 subtitle 已解决 |
您所在的位置:网站首页 › matlab subplot title在下 › Matlab subplot之后在中央上方加标题 subtitle 已解决 |
很常用的问题,准备好好考虑下 以前都是用text随便搞的 考虑方法 step1、 找到第一行几个子图的位置,确定title位置 step2、在该位置新建一个坐标轴,添加title并隐藏坐标轴 如下 使用说明: ht:title的句柄,如果需要修改字体大小颜色等可以引用 kn:subplot的列数 text: 需要添加的标题 ====================================== function ht = subtitle(kn,text)% SUBTITLE ht = subtitle(kn,text)% Input:% kn Number of subplot columns% text Title of the graph% Output:% ht Handle of this title% Note: % Vertical colorbar should be included in kn %% Example:% for kk = 1:6% subplot(2,3,kk);% plot(magic(3));% end% ht = subtitle(3,'title in the middle top')% % Last revised 2011-04-15h1 = get(gcf,'children');axis1 = get(h1(end),'Position');axis2 = get(h1(end-kn+1),'Position');axest = [axis1(1),axis1(2)+axis1(4),1-axis1(1)-(1-axis2(1)-axis2(3)),0.01];ht = axes('Position',axest);axis(ht,'off')title(ht,text)
========================== 把上述内容保存为subtitle.m 文件,放到toolbox 或者当前文件夹下运行即可。 注意事项:前几天绘图时发现,如果每个subplot上还绘制了colorbar,那么这个colorbar也要算在kn里 比如3行2列,每个图都有colorbar,那么就要kn写4,这样才能保证文字在最中间。 先绘制subplot,都画完之后,再使用subtitle命令 ht = subtitle(4,'make the title in middle top') 如果绘图时采用subplot('position',[ ]) 这样的方式 不能保证函数正确,函数是按照subplot默认的顺序提取子图坐标以自动计算居中位置的 2013年新改了一个版本 http://hi.baidu.com/curbzz/item/c0a2e9f7bf6f23ca0dd1c885 可以支持position这样的方式,如果有问题欢迎反馈 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |